﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using OgilvyOne.DALFactory;
using OgilvyOne.Model;

namespace OgilvyOne.BLL
{
    /// <summary>
    /// 文章标签,获取指定文章属性值
    /// <cms:article value="属性名" id="文章ID"></cms:article>
    /// </summary>
    class ArticleLabel : CommonLabel
    {
        public ArticleLabel(CommonModel model)
            : base(model)
        {

        }

        private int aid;

        public int Aid
        {
            set { aid = value; }
            get { return aid; }
        }

        public override string GetLabelHtml()
        {
            CmsArticleModel cm = CmsArticleFrontFactory.create().getCmsArticle(aid);
            if (cm == null) return "<font color='red'>文章不存在!</font>";
            //
            try
            {
                if (MethodName == null || MethodName == "") return LabelStr + "<font color='red'>需要MethodName</font>";

                return cm.GetType().InvokeMember(MethodName, BindingFlags.GetProperty, null, cm, null).ToString();
            }
            catch
            {
                return "调用<" + MethodName + ">方法出错!";
            }
            
        }
    }
}
